package com.ldw.controller;

import com.ldw.common.Constans;
import com.ldw.service.ArticleService;
import com.ldw.vo.ArticleParam;
import com.ldw.vo.PageParams;
import com.ldw.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //首页 文章列表
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }

    @PostMapping("/hot")
    public Result hotArticle() {
        return articleService.hotArticle(Constans.limit);
    }

    @PostMapping("/new")
    public Result newArticle() {
        return articleService.newArticle(Constans.limit);
    }

    @PostMapping("/listArchives")
    public Result listArchives() {
        return articleService.listArchives();
    }

    @PostMapping("/view/{id}")
    public Result articleView(@PathVariable("id") long articleId) {
        return articleService.articleView(articleId);
    }

    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam) {
        return articleService.publish(articleParam);
    }
}
